package net.celisdelafuente.java.Acacia.pages;

import java.sql.SQLException;

import javax.servlet.http.HttpServletRequest;

import org.apache.click.ActionListener;
import org.apache.click.Control;
import org.apache.click.control.ActionLink;
import org.apache.click.element.CssImport;
import org.apache.click.element.JsImport;
import org.apache.click.extras.control.Menu;
import org.apache.click.extras.security.AccessController;
import org.apache.click.extras.security.RoleAccessController;

import com.j256.ormlite.jdbc.JdbcConnectionSource;

public class BorderTemplate extends BasePage {
	
	public String pageTitle = "Acacia";
	
	private ActionLink createSchema = new ActionLink("createSchema");
	private ActionLink dropSchema = new ActionLink("dropSchema");
	private Menu rootMenu = new MenuBuilder().buildMenu();
	//private PageLink goSuppliers = new PageLink("goSuppliers",SupplierPage.class);
	//private PageLink goBooks = new PageLink("goBooks", Book)

	public BorderTemplate() {
		CssImport csImport = new CssImport("/acacia.css");
		getHeadElements().add(csImport);
		JsImport jsImport = new JsImport("/js/jquery-1.7.1.min.js");
		getHeadElements().add(jsImport);
		
		if(rootMenu == null) {
			rootMenu = new MenuBuilder().buildMenu();
		}
		
	}
	
	public String getTemplate() {
		return "/border-template.htm";
	}
	
	public void onInit() {
		super.onInit();
		addControl(createSchema);
		
		createSchema.setActionListener(new ActionListener() {

			@Override
			public boolean onAction(Control source) {
				try {
					JdbcConnectionSource connectionSource = 
						(JdbcConnectionSource) GetConnection();
					CreateSchema(connectionSource);
					connectionSource.close();
					String msg = "ControlListenerPage#" + hashCode()
	                 + " Base de Datos Creada.";
	                 addModel("msg", msg);
					return true;
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}				
				return false;
			}
		});
	}

}
